// pages/afterSaleCente/afterSaleCente.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    type: 0,
    choose:0,
    count:1524,
    chooseCard:0,
    cards:[],
    choo_modal: "none"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //获取手机高度
    this.setData({
      navH: app.globalData.navHeight,
      productIdAndNumList: options.productIdAndNumList,
      addressId: options.addressId,
      type: options.type,
      couponId: options.couponId,
      remark: options.remark,
      banlance: options.banlance,
      groupShoppingId: options.groupShoppingId,
      giftCardWay: options.giftCardWay,
      price1: options.price1,
      shoppingCart: options.shoppingCart,
      myOrder: options.myOrder,
      orderId: options.orderId,
      orderid: options.orderId,
      communityGroup: options.communityGroup,
      communityheadid: options.communityheadid,
      typeShow: options.typeShow,
      promotionId:options.promotionId,
      deduct: options.deduct,
      balance: wx.getStorageSync("balance")
    })
    wx.showLoading({
      title: '正在查询...',
      icon: 'loading',
    })
    wx.request({
      url: app.globalData.url + 'getJinHeYiKaTongMemberCards',
      method: 'GET',
      data: {
        userId:wx.getStorageSync("userId")
      },
      success: function (res) {
        wx.hideLoading();
        if (res.data.result == 0) {
          wx.showToast({
            title: res.data.errmsg,
            icon: 'none'
          })
          return;
        }
        if (res.data.result == 1&&res.data.data.cardsJson.code != 200) {
          wx.showToast({
            title: res.data.data.cardsJson.message,
            icon: 'none'
          })
          return;
        }
        let cards = res.data.data.cardsJson.data.cardList;
        if(cards&&cards.length>0){
          that.setData({
            cards: cards,
          });
        }else{
          wx.showToast({
            title: '未查询到用户卡包列表',
            icon: 'none'
          })
          return;
        }
      },
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  navBack: function () {
    wx.navigateBack({
    })
  },
  toDetail: function () {
    var that = this;
    wx.navigateTo({
      url: '/pages/productDetail/productDetail?productid=' + that.data.product.product.productId,
    })
  },
  add: function () {
    var count  = this.data.count;
    count++;
    this.setData({
      count:count,
      price: this.data.storedValueCardList[this.data.chooseCard].price*count
    })
  },
  reduce: function () {
    var count = this.data.count;
    count--;
    if(count>0){
      this.setData({
        count: count,
        price: this.data.storedValueCardList[this.data.chooseCard].price * count
      })
    }
  },
  chooseThisCard: function (e) {
    if (this.data.chooseCard != e.currentTarget.dataset.index){
      this.setData({
        chooseCard: e.currentTarget.dataset.index
      })
    }
  },
  goMyCard: function () {
    wx.navigateTo({
      url: '/pages/myStoredValue/myStoredValue'
    })
  },
  getCurrent:function(e){
    var cur = e.detail.current;    //有兴趣的小伙伴可以打印e,瞅瞅它长啥样
    this.setData({
      choose: cur
    })
 },
 
  // 弹出
  modal_s: function (e) {
    this.setData({
      choo_modal: "block"
    });
  },
  //消失
  modal_n: function () {
    this.setData({
      choo_modal: "none"
    });
  },
  buy: function(e) {
    var that = this;
    if(!that.data.cards||that.data.cards.length==0){
      wx.showToast({
        title: "未查询到用户卡片",
        icon: 'none'
      })
      return;
    }else{
      let cardId = that.data.cards[that.data.chooseCard].id;
      let cartNo = that.data.cards[that.data.chooseCard].jhCode;
      let cartMoney = that.data.cards[that.data.chooseCard].balance;
      wx.navigateTo({
        url: '/pages/cashier/cashier?jinHeCardId=' + cardId+'&jinHeCardNo='+cartNo+'&jinHeCardMoney='+cartMoney+'&productIdAndNumList='+that.data.productIdAndNumList+'&addressId='+that.data.addressId+'&type='+that.data.type
        +'&couponId='+that.data.couponId+'&remark='+that.data.remark+'&banlance='+that.data.banlance+'&groupShoppingId='+that.data.groupShoppingId+'&giftCardWay='+that.data.giftCardWay
        +'&price1='+that.data.price1+'&shoppingCart='+that.data.shoppingCart+'&myOrder='+that.data.myOrder+'&orderId='+that.data.orderId+'&orderid='+that.data.orderId
        +'&communityGroup='+that.data.communityGroup+'&communityheadid='+that.data.communityheadid+'&typeShow='+that.data.typeShow+'&promotionId='+that.data.promotionId+'&deduct='+that.data.deduct,
      })
    }
  },
  
})